<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ServerStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|max:10',
            'domain' => 'required|alpha_num|min:3|max:15|unique:server|not_in:www,admin,demo,china,sex,fuck',
            'server_host' => 'required',
            'server_port' => 'required|numeric|between:1000,99999',
            'auth_port' => 'required|numeric|between:1000,99999',
            'db_host' => 'required',
            'db_port' => 'required|numeric|between:1000,99999',
            'db_acc' => 'required|max:15',
            'db_pwd' => 'required|max:30',

            'soap_host' => 'required',
            'soap_port' => 'required|numeric|between:1000,99999',
            'soap_acc' => 'required|max:15',
            'soap_pwd' => 'required|max:30',

            'bt_url' => 'required|max:50',
            'bt_key' => 'required|max:50',
        ];
    }

    public function messages()
    {
        return [
            'name.required'=>'服务器名称必填',
//            'domain.required'=>'域名必填',
            'domain.not_in'=>'关键字不能使用',
            'server_host.required'=>'服务器地址必填',
            'server_port.required'=>'世界服务端口必填',
            'auth_port.required'=>'登录服务端口必填',
            'db_host.required'=>'数据库地址必填',
            'db_port.required'=>'数据库端口必填',
            'db_acc.required'=>'数据库用户名必填',
            'db_pwd.required'=>'数据库密码必填',

            'soap_host.required'=>'通讯地址必填',
            'soap_port.required'=>'通讯端口必填',
            'soap_acc.required'=>'GM账号必填',
            'soap_pwd.required'=>'GM账号密码必填',

            'name.max'=>'服务器名称最多 :max 个字符',
            'domain.min'=>'域名最少 :min 个字符',
            'domain.max'=>'域名最多 :max 个字符',
            'domain.alpha_num'=>'域名只能包含字母和数字',
            'domain.unique'=>'此域名已经被使用，请更换其他域名',

//            'server_host.ip'=>'错误的ip地址',
//            'db_host.ip'=>'错误的ip地址',

            'server_port.between'=>'错误的端口号',
            'auth_port.between'=>'错误的端口号',
            'db_port.between'=>'错误的端口号',
            'soap_port.between'=>'错误的端口号',

            'db_acc.max'=>'用户名最多 :max 个字符',
            'db_pwd.max'=>'密码最多 :max 个字符',

            'soap_acc.max'=>'GM账号最多 :max 个字符',
            'soap_pwd.max'=>'GM账号密码最多 :max 个字符',

            'bt_url.required'=>'文件管理地址必填',
            'bt_key.required'=>'文件管理密钥必填',

            'bt_url.max'=>'文件管理地址最多 :max 个字符',
            'bt_key.max'=>'文件管理密钥最多 :max 个字符',

        ];
    }
}
